const path = require('path')
const webpack = require('webpack')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
// const CompressionPlugin = require('compression-webpack-plugin') //开启gzip压缩
const APIHOST = process.env.APIHOST
module.exports = {
  publicPath: 'Koa2', // 部署应用时的根路径
  // 输出文件目录
  outputDir: '../Koa2/public',
  // eslint-loader 是否在保存的时候检查
  assetsDir: 'public',  // 放置生成的静态资源(css,img,fonts)
  lintOnSave: process.env.NODE_ENV !== 'production',
  // use the full build with in-browser compiler?
  // https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
  // compiler: false,
  // webpack配置
  // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
  chainWebpack: () => {},
  // configureWebpack: config => {
  //   if (process.env.NODE_ENV === 'production') {
  //     config.mode = 'production'
  //     return {
  //       plugins: [new CompressionPlugin({
  //         test: /\.js$|\.html$|.css/,
  //         threshold: 10240, // 对超过10k的数据进行压缩
  //         deleteOriginalAssets: false	//是否删除原文件
  //       })]
  //     }
  //   } else {
  //     config.mode = 'development'
  //   }
  //   Object.assign(config, {
  //     // 开发生产共同配置
  //     resolve: {
  //       alias: {
  //         '@': path.resolve(__dirname, './src')
  //       }
  //     }
  //   })
  // },
  configureWebpack: {
    // __APIHOST__: JSON.stringify(APIHOST)
    plugins: [
      new BundleAnalyzerPlugin(),
      new webpack.DefinePlugin({
        __APIHOST__: JSON.stringify(APIHOST),
      })
    ]
  },
  // vue-loader 配置项
  // https://vue-loader.vuejs.org/en/options.html
  // vueLoader: {},
  // 生产环境是否生成 sourceMap 文件
  productionSourceMap: false,
  // css相关配置
  css: {
   // 是否使用css分离插件 ExtractTextPlugin
   extract: true,
   // 开启 CSS source maps?
   sourceMap: false,
   // css预设器配置项
   loaderOptions: {},
   // 启用 CSS modules for all css / pre-processor files.
   modules: false
  },
  // use thread-loader for babel & TS in production build
  // enabled by default if the machine has more than 1 cores
  parallel: require('os').cpus().length > 1, //构建时开启多进程处理babel编译
  // 是否启用dll
  // See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
  // dll: false,
  // PWA 插件相关配置
  // see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
  pwa: {},
  // webpack-dev-server 相关配置
  devServer: {
   open: false, //浏览器自动打开页面
   host: '0.0.0.0',
   port: 8080,
   https: false,
   hotOnly: false,
   proxy: {
     '/api': {
       target: APIHOST,
       secure: false,
       changeOrigin: true,
       ws: true,
       pathRewrite: {
         '^/api': ''
       }
     }
   }, // 设置代理
   before: app => {}
  },
  // 第三方插件配置
  pluginOptions: {
   // ...
  }
 }